{extend name="admin@public/main"}
{block name="buttons"}
{if hasAuth('admin/user/add')}
<button class = "btn btn-sm btn-outline-primary" data-action="dialog" data-action-url="{:url('admin/user/add')}" data-dialog-title="新增用户">新增用户</button>
{/if}
{/block}
{block name="content"}
<form class = "data-search-form" method="get">
    <table class = "table">
        <thead>
        <tr class = "title">
            <th>用户名</th>
            <th>邮箱</th>
            <th>手机号</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <tr>
            <th>
                <input type="text" name = "username" class = "form-control-plaintext search-input"  value = "{$where.username|default=''}" placeholder="请输入搜索的用户名"/>
            </th>
            <th>
                <input type="text" name ="email" class = "form-control-plaintext search-input" value = "{$where.email|default=''}" placeholder="请输入搜索的邮件"/>
            </th>
            <th>
                <input type="text" name="mobile" class = "form-control-plaintext search-input" value = "{$where.mobile|default=''}" placeholder="请输入搜索的手机号码"/>
            </th>
            <th>
                <select name = "valid" class = "form-control-plaintext search-input">
                    <option value = ""></option>
                    <option value = "1" {if condition="isset($where.valid) and $where.valid eq 1"}selected{/if}>启用</option>
                    <option value = "2" {if condition="isset($where.valid) and $where.valid eq 2"}selected{/if}>禁用</option>
                </select>
            </th>
            <th></th>
        </tr>
        </thead>
        {php}$user_status = ['','启用','禁用'];{/php}
        <tbody>
            {if empty($list)}
            <tr>
                <td colspan = "5" class = "empty-list"><span class = "glyphicon glyphicon-inbox"></span>没有任何记录</td>
            </tr>
            {else}
            {volist name="list" id="vo"}
            <tr>
                <td>{$vo.username|default=''}</td>
                <td>{$vo.email|default=''}</td>
                <td>{$vo.mobile|default=''}</td>
                <td>{$user_status[$vo.valid]}</td>
                <td>
                    {if hasAuth('admin/user/edit')}
                    <span class="text-explode">|</span>
                    <a class = "user-option" data-action = "dialog" data-action-url="{:url('admin/user/edit',['id'=>$vo.id])}"  data-dialog-title="编辑用户">编辑</a>
                    {/if}
                    {if hasAuth('admin/user/auth')}
                    <span class = "text-explode">|</span>
                    <a class = "user-option" data-action = "dialog" data-action-url="{:url('admin/user/auth',['id'=>$vo.id])}" data-dialog-title="用户授权">授权</a>
                    {/if}
                    {if hasAuth('admin/user/password')}
                    <span class = "text-explode">|</span>
                    <a class = "user-option" data-action = "dialog" data-action-url="{:url('admin/user/password',['id'=>$vo.id])}" data-dialog-title="密码重置">密码</a>
                    {/if}
                    {if hasAuth('admin/user/forbid')}
                    <span class="text-explode">|</span>
                    {if condition="$vo.valid eq 1"}
                    <a class = "user-option" data-action = "ajax" data-action-url="{:url('admin/user/forbid')}"
                       data-action-params = '{"id":{$vo.id},"field":"valid","value":2}' data-action-method = "post">禁用</a>
                    {else}
                    <a class = "user-option" data-action = "ajax" data-action-url="{:url('admin/user/forbid')}"
                       data-action-params = '{"id":{$vo.id},"field":"valid","value":1}' data-action-method = "post">启用</a>
                    {/if}
                    {/if}
                    {if hasAuth('admin/user/del')}
                    <span class="text-explode">|</span>
                    <a class = "user-option" data-action = "ajax" data-action-url="{:url('admin/user/del')}"
                       data-action-params = '{"id":{$vo.id},"field":"delete"}' data-action-ask = "是否确定删除用户:{$vo.username}" data-action-method = "post">删除</a>
                    {/if}

                </td>
            </tr>
            {/volist}
            {/if}
        </tbody>
    </table>
    {$list->render()}
</form>
{/block}